package exception;

import java.io.Console;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.Scanner;

public class UserTest
{
    public static void main(String[] args)
    {
        Console console = System.console();
        if (console == null) {
            System.out.println("No console available");
            return;
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("name = ");
        String name = scanner.nextLine();

//        char[] password = console.readPassword("pwd = ");
        System.out.println("pwd = ");
        String pwd = scanner.nextLine();

        System.out.println("nick = ");
        String nick = scanner.nextLine();
        System.out.println("age = ");
        int age = scanner.nextInt();
        User user = new User(name,pwd,nick,age);
        String objName = name+".obj";
        try(FileOutputStream fos = new FileOutputStream(objName);
            ObjectOutputStream Oos = new ObjectOutputStream(fos))
        {
            Oos.writeObject(user);
            System.out.println("write object successfully");
        }catch (Exception e)
        {
            e.printStackTrace();
        }


    }
}
